import datetime
import numpy as np
def date2Str(nowDate):
    nowDate=str(nowDate,'GB2312')
    return datetime.datetime.strptime(\
        nowDate,"%Y/%m/%d").date().weekday()+1

days,closing_price=np.loadtxt('stock.csv',\
                              delimiter=',',\
                              usecols=(1,2),\
                              converters={1:date2Str},\
                              unpack=True)
for i in range(days.size):
    print("发生交易的天数是星期%d,按天收盘价是%f"\
          %(days[i],closing_price[i]))
price_avg=np.zeros(5)
for i in range(1,6):
    index=np.where( days == i)
    price=np.take(closing_price,index)
    avg=np.mean(price)
    price_avg[i-1]=avg
    print('星期',i,'的平均收盘价是：',price_avg[i-1])

